<template>
	<el-container>
		<el-header>
			<div class="left-panel">
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="部门名称" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="deptId" hidePagination>
				<el-table-column label="部门名称" prop="deptName" width="200"></el-table-column>
				<el-table-column label="别名" prop="alias" width="150"></el-table-column>
				<el-table-column label="部门领导" prop="deptLeadName" width="150"></el-table-column>
				<el-table-column label="排序" prop="sortNo" width="150"></el-table-column>
				<el-table-column label="状态" prop="status" width="100">
					<template #default="scope">
						<el-tag v-if="scope.row.wDeptId==''||scope.row.wDeptId==undefined" type="danger">未绑定</el-tag>
						<el-tag  v-else type="success">已绑定</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="微信部门ID" prop="wDeptId" width="150"></el-table-column>
				<el-table-column label="备注" prop="remark" min-width="300"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="100">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)" v-if="scope.row.wDeptId==''||scope.row.wDeptId==undefined">同步</el-button>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)" v-else>更新</el-button>
						</el-button-group>
					</template>
				</el-table-column>

			</scTable>
		</el-main>
	</el-container>


</template>

<script>

export default {
	name: 'WeiXin Dept Sync',
	components: {
	},
	data() {
		return {
			apiObj: this.$API.system.unitDept.list,
			search: {
				keyword: null
			}
		}
	},
	methods: {
		//编辑
		async table_edit(row) {
			var res = await this.$API.system.unitDept.syncWeiXinUnitDept.post({deptId:row.deptId});
			if (res.code == 200) {
				this.$message.success("操作成功");
				this.$refs.table.refresh();
			}else
			{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		upsearch(){
			this.$refs.table.upData(this.search)
		},
	}
}
</script>

<style>
</style>
